package org.client.otdr;

import org.openems.DoubleArray;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;

public class LocalMeasurer implements Measurer {
	private Client client;
	private WebResource webResource;

	public LocalMeasurer() {
		client = Client.create();
		client.setConnectTimeout(30*1000);
		client.setReadTimeout(30*1000);
		client.setFollowRedirects(Boolean.TRUE);
		webResource = client.resource("http://localhost:8081/rest/").path("otdr");
	}
	
	@Override
	public void start(String wavelength, String pulsewidth, MeasurerHandler handler) {
		DoubleArray ret = webResource.get(DoubleArray.class);
		
		Double[] data  = new Double[ret.data.size()];
		for (int i = 0; i < ret.data.size(); i++) {
			data[i] = ret.data.get(i);
		}
		handler.onUpdate(data);
	}

	@Override
	public void stop() {
		// TODO Auto-generated method stub
		
	}

}
